/**
 * @PROJECT 
 * @DATE 2018年7月14日 上午12:12:34
 * @AUTHOR LUYU
 */
package com.kool.system.action.aut;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.kool.core.base.IBaseAction;
import com.kool.core.exception.AppException;
import com.kool.core.util.BeanUtils;
import com.kool.system.bean.SyReqAutBean;
import com.kool.system.bean.io.aut.SYAUTCODEXBean;
import com.kool.system.bean.io.req.SYREQINFYBean;
import com.kool.system.service.AutService;

/**
 * @DESCRIBE 查询权限绑定的请求
 * @AUTHOR LUYU
 * @DATE 2018年7月14日 上午12:12:34
 *
 */
@Controller
public class QueryAutReqAction implements IBaseAction {
	@Autowired
	private AutService service;

	/**
	 * @DESCRIBE
	 * @DATE 2018年7月13日 下午11:36:09
	 *
	 * @param sInput
	 * @return
	 * @throws AppException
	 */
	@Override
	@ResponseBody
	@RequestMapping(value = "/sys/aut/queryAutReq", method = RequestMethod.POST)
	public JSONObject doAction(@RequestBody String sInput) throws AppException {
		JSONObject pkgIn = JSONObject.parseObject(sInput);
		JSONArray secIn = pkgIn.getJSONArray("SYAUTCODEX");
		if (null == secIn || secIn.size() <= 0) {
			throw new AppException("SY000047");// 输入为空
		}
		JSONObject propIn = secIn.getJSONObject(0);
		SYAUTCODEXBean ioIn = JSON.toJavaObject(propIn, SYAUTCODEXBean.class);
		ioIn.validate();

		List<SyReqAutBean> list = service.queryAutReq(ioIn.getAutCode());

		JSONObject pkgOut = new JSONObject();
		JSONArray secOut = new JSONArray();
		for (SyReqAutBean menu : list) {
			SYREQINFYBean io = (SYREQINFYBean) BeanUtils.bean2Io(menu, SYREQINFYBean.class);
			secOut.add(JSON.toJSON(io));
		}
		pkgOut.put("SYREQINFY", secOut);
		return pkgOut;
	}

}
